/*
 * @Description:
 * @Author: Zzt
 * @Date: 2022-08-17 13:46:18
 * @LastEditTime: 2022-08-18 18:45:47
 */
import { createContext, useReducer, useEffect, useContext } from 'react';
import { SET_SELECTED_ITEM } from '../constants';
import { Button, Modal, Table } from 'antd';
import style from '../styles/context.module.scss';

import { BackupListReducer } from '../reducers/BackupListReducer';

const initialState = {
  selectItems: [],
  delId: [],
  discParameters: [{ id: 1, name: 'CD-70M', capacity: 740, company: 'M' }]
};

const BackupListContext = createContext();

const BackupListContextProvider = (props) => {
  const [state, dispatch] = useReducer(BackupListReducer, initialState);
  const actions = {
    /**
     * @description: 设置表格中选中条目的key
     * @param {*} selectArr
     * @return {*}
     */
    setSelectKey(selectArr) {
      dispatch({ type: SET_SELECTED_ITEM, data: selectArr });
    },
    remove(id) {
      console.log(id);
      Modal.confirm({
        title: '取消备份',
        okText: '确认',
        cancelText: '取消',
        content: <div>是否取消正在执行中的备份？（取消后，已经备份的数据将被移除）</div>,
        // footer:{[<><Button>取消</Button><Button>确认删除</Button></>]},
        // onOk() {
        //   const ids = id instanceof Array ? id.join(',') : id;
        //   deleteBackup(ids).then((res) => {
        //     const data = res.data.map((item) => parseInt(item, 10));
        //     dispatch({ type: DELETE_PLAN_ITEM, ids: data });
        //   });
        // },
        onCancel() {
          console.log('Cancel');
        }
      });
    },
    /* 删除xx备份 */
    delBackup(delId) {
      console.log(delId);
    },
    /* 手动备份 */
    manual(id) {
      console.log('Fun', id);
      Modal.confirm({
        title: '手动备份',
        okText: '确认',
        cancelText: '取消',
        content: (
          <div className={style.modal}>
            <div>您正在执行手动执行备份，备份过程详见【备份清单】</div>
          </div>
        )
        // footer:{[<><Button>取消</Button><Button>确认删除</Button></>]},
        // onOk() {
        //   const ids = id instanceof Array ? id.join(',') : id;
        //   deleteBackup(ids).then((res) => {
        //     const data = res.data.map((item) => parseInt(item, 10));
        //     dispatch({ type: DELETE_PLAN_ITEM, ids: data });
        //   });
        // },
        // onCancel() {
        //   console.log('Cancel');
        // }
      });
    },
    /* 光盘参数 */
    parameter() {
      Modal.confirm({
        title: '光盘参数',
        width: 700,
        // okText: '确认',
        // cancelText: '取消',
        content: (
          <>
            <div>
              已有光盘参数列表<Button>添加</Button>
            </div>
            <Table>
              <Modal title="序号" key="id"></Modal>
              <Modal title="光盘名称" key="name"></Modal>
              <Modal title="光盘容量" key="capacity"></Modal>
              <Modal title="单位" key="company"></Modal>
              <Modal title="创建人" key="buildBy"></Modal>
              <Modal title="创建时间" key="time"></Modal>
              <Modal title="操作" key="active"></Modal>
            </Table>
          </>
        )
        // footer:{[<><Button>取消</Button><Button>确认删除</Button></>]},
        // onOk() {
        //   const ids = id instanceof Array ? id.join(',') : id;
        //   deleteBackup(ids).then((res) => {
        //     const data = res.data.map((item) => parseInt(item, 10));
        //     dispatch({ type: DELETE_PLAN_ITEM, ids: data });
        //   });
        // },
        // onCancel() {
        //   console.log('Cancel');
        // }
      });
    }
  };
  useEffect(() => {}, []);
  return (
    <BackupListContext.Provider value={{ ...state, ...actions }}>
      {props.children}
    </BackupListContext.Provider>
  );
};
export const useBackupListContext = () => {
  return useContext(BackupListContext);
};
export { BackupListContext, BackupListContextProvider };
